import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import { TextTag } from '../../texts/entities/text-tag.entity';
import { User } from '../../common/entities/user.entity';

@Entity('tags')
export class Tag {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'user_id', type: 'int', comment: '用户ID' })
  userId: number;

  @Column({ type: 'varchar', length: 50, comment: '标签名称' })
  name: string;

  @Column({ type: 'varchar', length: 7, default: '#3498db', comment: '标签颜色' })
  color: string;

  @CreateDateColumn({ 
    name: 'createdAt',
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP',
    comment: '创建时间'
  })
  createdAt: Date;

  @UpdateDateColumn({ 
    name: 'updatedAt',
    type: 'timestamp',
    precision: 0,
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
    comment: '更新时间'
  })
  updatedAt: Date;

  @ManyToOne(() => User, user => user.tags)
  @JoinColumn({ name: 'user_id' })
  user: User;

  @OneToMany(() => TextTag, textTag => textTag.tag)
  textTags: TextTag[];
}